package com.software_product_construction.backend_software_product_construction.service.impl;

import com.software_product_construction.backend_software_product_construction.dao.SuperMapper;
import com.software_product_construction.backend_software_product_construction.pojo.Lessee;
import com.software_product_construction.backend_software_product_construction.pojo.User;
import com.software_product_construction.backend_software_product_construction.service.SuperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SuperServiceImpl implements SuperService {
    @Autowired
    SuperMapper superMapper;



    @Override
    public List<Lessee> getLesseeList(String name,Integer from, Integer to) {
        to = to-from+1;
        from = from-1;

        return superMapper.getLesseeList(name, from, to);
    }

    @Override
    public boolean  deleteLesseeById(String id){
        List<Lessee> lessees = getAllLessee();

        boolean judge = false;
        for(Lessee lessee : lessees){
            if(lessee.getId().equals(id)){
                judge = true;
            }
        }
        if(judge){
            superMapper.deleteLesseeById(id);
        }
        return judge;
    }

    @Override
    public List<Lessee> getAllLessee() {

        return superMapper.getAllLessee();
    }

    @Override
    public boolean modifyLesseeInfo(String id, String password, String nickname,Integer sex) {
        List<Lessee> lessees = getAllLessee();

        boolean judge = false;
        for(Lessee lessee : lessees){
            if(lessee.getId().equals(id)){
                judge = true;
            }
        }
        if(judge){
            superMapper.modifyLesseeInfo(id,password,nickname,sex);
        }
        return judge;

    }
    @Override
    public List<User> getUserList(String name, Integer from, Integer to) {
        to = to-from+1;
        from = from-1;
        return superMapper.getUserList(name, from, to);
    }

}
